﻿namespace Luka;

/// <summary>
/// 缓存操作类
/// Microsoft.Extensions.Caching.StackExchangeRedis
/// </summary>
public interface ICacheHandler
{
    #region 设置缓存

    /// <summary>
    /// 添加缓存
    /// </summary>
    /// <param name="key">键名</param>
    /// <param name="value">值</param>
    /// <param name="minutes">有效时间</param>
    void SetString(string key, string value, int minutes = 120);

    /// <summary>
    /// 添加缓存(Async)
    /// </summary>
    /// <param name="key">键名</param>
    /// <param name="value">值</param>
    /// <param name="minutes">有效时间（默认120分钟）</param>
    Task SetStringAsync(string key, string value, int minutes = 120);

    /// <summary>
    /// 添加缓存
    /// </summary>
    /// <param name="key">键名</param>
    /// <param name="value">值</param>
    /// <param name="minutes">有效时间（默认120分钟）</param>
    void Set<T>(string key, T value, int minutes = 120) where T : class, new();

    /// <summary>
    /// 添加缓存(Async)
    /// </summary>
    /// <param name="key">键名</param>
    /// <param name="value">值</param>
    /// <param name="minutes">有效时间（默认120分钟）</param>
    void SetAsync<T>(string key, T value, int minutes = 120) where T : class, new();

    #endregion 设置缓存

    #region 获取缓存

    /// <summary>
    /// 检查给定 key 是否存在
    /// </summary>
    /// <param name="cacheKey">键</param>
    /// <returns></returns>
    bool Exists(string cacheKey);

    /// <summary>
    /// 检查给定 key 是否存在(Async)
    /// </summary>
    /// <param name="cacheKey">键</param>
    /// <returns></returns>
    Task<bool> ExistsAsync(string cacheKey);

    /// <summary>
    /// 获取缓存
    /// </summary>
    /// <param name="key">键名</param>
    /// <returns></returns>
    string GetString(string key);

    /// <summary>
    /// 获取缓存(Async)
    /// </summary>
    /// <param name="key">键名</param>
    /// <returns></returns>
    Task<string> GetStringAsync(string key);

    /// <summary>
    /// 获取缓存
    /// </summary>
    /// <param name="key">键名</param>
    /// <returns></returns>
    T Get<T>(string key) where T : class, new();

    /// <summary>
    /// 获取缓存(Async)
    /// </summary>
    /// <param name="key">键名</param>
    /// <returns></returns>
    Task<T> GetAsync<T>(string key) where T : class, new();

    #endregion 获取缓存

    #region 删除缓存

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="key">键名</param>
    void Remove(string key);

    /// <summary>
    /// 删除（Async）
    /// </summary>
    /// <param name="key">键名</param>
    void RemoveAsync(string key);

    #endregion 删除缓存

    #region 刷新缓存

    /// <summary>
    /// 刷新缓存
    /// </summary>
    /// <param name="key"></param>
    /// <param name="minutes"></param>
    void Refresh(string key, int minutes = 120);

    /// <summary>
    /// 刷新缓存（Async）
    /// </summary>
    /// <param name="key"></param>
    /// <param name="minutes"></param>
    void RefreshAsync(string key, int minutes = 120);

    #endregion 刷新缓存
}